// CameraWin.h
#ifndef CAMERAWIN_H
#define CAMERAWIN_H

#include <QWidget>
#include <QAtomicInt>
#include <QElapsedTimer>
#include "v4l2api.h"
#include "qwenvl.h"  // 阿里大模型头文件
#include <QDebug>

namespace Ui {
class CameraWin;
}

class CameraWin : public QWidget
{
    Q_OBJECT

public:
    explicit CameraWin(QWidget *parent = nullptr);
    ~CameraWin();

signals:
    void jumpToWidget();

private slots:
    void on_cameraBackBtn_clicked();
    void on_openCamera_clicked();
    void on_closeCamera_clicked();
    void handleFrame(QImage frame);

    void on_getImg_clicked();

private:
    Ui::CameraWin *ui;
    V4l2Api *m_camera = nullptr;            // 摄像头设备对象
    QAtomicInt m_cameraActive;              // 原子操作状态标志
    QElapsedTimer m_releaseTimer;           // 设备释放计时器

    void safeCameraShutdown();              // 安全关闭摄像头资源
    bool isDeviceAvailable() const;        // 检查设备是否可用
};

#endif // CAMERAWIN_H
